package cn.rkylin.oms.order.vo;

import cn.rkylin.oms.common.consts.YesNoConst;
import cn.rkylin.oms.order.domain.OrderSku;

import java.math.BigDecimal;

public class OrderSkuVO extends OrderSku {
    private String action;
    private String skuProperty;
    private Integer waittingShip;
    private String addShippingQty;//发货数量，因为是累计的所以追加这个变量
    private String emptyLgstCompany;//生成发货单的时候需要确认信息，y是可以为空，n不可以为空，null或者空字符串忽略该检查(物流公司为空，是否确认分派？)
    private String hasrefund;//生成发货单的时候需要确认信息，y是可以为空，n不可以为空，null或者空字符串忽略该检查(当前订单存在未废弃的退款单，是否确认分派？)
    private String orderStatusForWher;
    private String deleteAction;
    private static final String OPERATION_BTN_DEL = "<a href=\"javascript:;\" class=\"delete\" orderskuid=\"%s\" pepid='sysOrderSkuDelete'>删除</a>&nbsp;<a href=\"javascript:;\" class=\"replace\" orderskuid=\"%s\" pepid='sysOrderSkuReplace'>替换</a>";//"<button onclick=\"delOrderSku(\'%s\')\" orderId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs\"><i class=\"fa fa-edit\"></i>&nbsp;删除</button>";
    private static final String OPERATION_BTN_DEL_WITHOUT_REPLACE = "<a href=\"javascript:;\" class=\"delete\" orderskuid=\"%s\" pepid='sysOrderSkuDelete'>删除</a>";//"<button onclick=\"delOrderSku(\'%s\')\" orderId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs\"><i class=\"fa fa-edit\"></i>&nbsp;删除</button>";
    private static final String OPERATION_BTN_BACK = "<a href=\"javascript:;\" class=\"back\" orderskuid=\"%s\" pepid='sysOrderSkuBack'><font style=\"color:red\">恢复</font></a>";
    
    /**
     * danjuType:商品所属的单据类型.
     */
    private String danjuType;
    /**
     * shangpinType:商品类型.
     */
    private String shangpinType;
    /**
     * shangpinType:商品类型.
     */
    private String sourceSkuId;
    /**
     * sourceId:.
     */
    private String sourceId;
    
    public String getSourceSkuId() {
        return sourceSkuId;
    }

    public void setSourceSkuId(String sourceSkuId) {
        this.sourceSkuId = sourceSkuId;
    }

    public String getDanjuType() {
        return danjuType;
    }

    public void setDanjuType(String danjuType) {
        this.danjuType = danjuType;
    }

    public String getShangpinType() {
        return shangpinType;
    }

    public void setShangpinType(String shangpinType) {
        this.shangpinType = shangpinType;
    }

    public String getDeleteAction() {
        StringBuffer opButton = new StringBuffer();
        if ("au".equals(this.getOperStus())){
            return "";
        } else {
            if ("y".equals(this.getDeleted())){
                    opButton.append(String.format(OPERATION_BTN_BACK, getOrderSkuId(), getOrderSkuId()));
                    opButton.append("&nbsp;");
            } else {
                String appendBtn = OPERATION_BTN_DEL;
                if(YesNoConst.YES.equals(this.getIsGift())) {
                    appendBtn = OPERATION_BTN_DEL_WITHOUT_REPLACE;
                    
                }
                opButton.append(String.format(appendBtn, getOrderSkuId(), getOrderSkuId()));
                opButton.append("&nbsp;");
            }    
        }
        return opButton.toString();
    }

    public void setDeleteAction(String deleteAction) {
        this.deleteAction = deleteAction;
    }

    private String operStus;
    
    public String getOperStus() {
        return operStus;
    }

    public void setOperStus(String operStus) {
        this.operStus = operStus;
    }

//    public String getOrderSkuId() {
//        return orderSkuId;
//    }
//
//    public void setOrderSkuId(String orderSkuId) {
//        this.orderSkuId = orderSkuId;
//    }

    /**
     * actualAmount:实际金额.
     */
    private String actualAmount;
    /**
     * actualPayPrice:实际支付单价.
     */
    private String actualPayPrice;

    /**
     * operation:操作.
     */
    private String operation;

    public String getOrderStatusForWher() {
        return orderStatusForWher;
    }

    public void setOrderStatusForWher(String orderStatusForWher) {
        this.orderStatusForWher = orderStatusForWher;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getActualAmount() {
        if (getQty()==null || getFactUnitPrice()==null)
            return null;
        
        BigDecimal result = getFactUnitPrice().multiply(new BigDecimal(getQty()));

        return result.toString();
    }

    public void setActualAmount(String actualAmount) {
        this.actualAmount = actualAmount;
    }

    public String getActualPayPrice() {

        if (getQty()!=null && getQty()!=0){
            BigDecimal qty = new BigDecimal(getQty().intValue());
            BigDecimal result = getDivideOrderFee()==null?BigDecimal.ZERO:getDivideOrderFee().divide(qty,2, BigDecimal.ROUND_HALF_UP);
            return result.toString();
        } else {
            return "";
        }
       

    }

    public void setActualPayPrice(String actualPayPrice) {
        this.actualPayPrice = actualPayPrice;
    }

    public Integer getWaittingShip() {
        int qty = this.getQty() != null ? this.getQty().intValue() : 0;
        int shippingQty = this.getShippingQty() != null ? this.getShippingQty().intValue() : 0;
        int shipedQty = this.getShipedQty() != null ? this.getShipedQty().intValue() : 0;

        return qty - shippingQty - shipedQty;
    }

    public void setWaittingShip(Integer waittingShip) {
        this.waittingShip = waittingShip;
    }

    public String getSkuProperty() {
        if ("y".equals(this.getIsGift())) {
            return "赠";
        } else if ("y".equals(this.getIsVirt())) {
            return "虚";
        } else {
            return "销";
        }
    }

    public void setSkuProperty(String skuProperty) {
        this.skuProperty = skuProperty;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getAddShippingQty() {
        return addShippingQty;
    }

    public void setAddShippingQty(String addShippingQty) {
        this.addShippingQty = addShippingQty;
    }

    public String getEmptyLgstCompany() {
        return emptyLgstCompany;
    }

    public void setEmptyLgstCompany(String emptyLgstCompany) {
        this.emptyLgstCompany = emptyLgstCompany;
    }

    public String getHasrefund() {
        return hasrefund;
    }

    public void setHasrefund(String hasrefund) {
        this.hasrefund = hasrefund;
    }

    /**
     * 商品来源
     */
    private String skuSource;
    /**
     * 退入数量
     */
    private Integer returnQty;
    /**
     * 实际金额
     */
    private BigDecimal factMoney;

    /**
     * 复选框扩展
     */
    private String chk;
    /**
     * 实际支付单价
     */
    private BigDecimal divideGoodsFee;

    public void setSkuSource(String skuSource) {
        this.skuSource = skuSource;
    }

    public String getSkuSource() {
        return skuSource;
    }

    public Integer getReturnQty() {
        return returnQty;
    }

    public void setReturnQty(Integer returnQty) {
        this.returnQty = returnQty;
    }

    public BigDecimal getFactMoney() {
        if (getFactUnitPrice()==null || getQty()== null)
            return null;
        
        return getFactUnitPrice().multiply(BigDecimal.valueOf(getQty()));
    }

    public void setFactMoney(BigDecimal factMoney) {
        this.factMoney = factMoney;
    }

    public String getChk() {
        return chk;
    }

    public void setChk(String chk) {
        this.chk = chk;
    }

    public BigDecimal getDivideGoodsFee() {
        if ("订单".equals(this.getSkuSource())) {
            return getDivideOrderFee()==null?BigDecimal.ZERO.divide(BigDecimal.valueOf(getQty()), 2, BigDecimal.ROUND_HALF_UP):getDivideOrderFee().divide(BigDecimal.valueOf(getQty()), 2, BigDecimal.ROUND_HALF_UP);
        } else {
            return divideGoodsFee;
        }
    }

    public void setDivideGoodsFee(BigDecimal divideGoodsFee) {
        this.divideGoodsFee = divideGoodsFee;
    }

    /**
     * 订单编号扩展
     */
    private String orderCode;

    public String getOrderCode() {
        return orderCode;
    }

    public void setOrderCode(String orderCode) {
        this.orderCode = orderCode;
    }

    /**
     * 订单商品标记
     */
    private String isOrderSku;

    public String getIsOrderSku() {
        return isOrderSku;
    }

    public void setIsOrderSku(String isOrderSku) {
        this.isOrderSku = isOrderSku;
    }

    private String returnSkuId;

    public String getReturnSkuId() {
        return returnSkuId;
    }

    public void setReturnSkuId(String returnSkuId) {
        this.returnSkuId = returnSkuId;
    }
}
